﻿using System;
using System.Collections.Generic;
using SocialFront.Entities;
using SocialFront.Providers.Comment;
using umbraco.interfaces;

namespace SocialFront.Provider.Umbraco
{
    public class UmbracoTag : TagBase
    {
        public override void AddTags(List<Tag> tags, int nodeId)
        {
            foreach (Tag tag in tags)
            {
                umbraco.editorControls.tags.library.addTagsToNode(nodeId, tag.Name.Trim(), "Default");
            }
        }

        public override void AddTags(List<Tag> tags, int nodeId, string group)
        {
            foreach (Tag tag in tags)
            {
                umbraco.editorControls.tags.library.addTagsToNode(nodeId, tag.Name.Trim(), group);
            }
        }

        public override List<Tag> GetTags(int id)
        {
            return ConvertITagsToTags(umbraco.editorControls.tags.library.GetTagsFromNodeAsITags(id));
        }

        private List<Tag> ConvertITagsToTags(List<ITag> tags)
        {
            List<Tag> sfTags = new List<Tag>();
            foreach (ITag tag in tags)
            {
                sfTags.Add(ConvertITagToTag(tag));
            }
            return sfTags;
        }

        private Tag ConvertITagToTag(ITag tag)
        {
            Tag sfTag = new Tag
                            {
                                Id = tag.Id,
                                Group = tag.Group,
                                Name = tag.TagCaption
                            };
            return sfTag;
        }

        public override List<Tag> GetTags(Blog blog)
        {
            throw new NotImplementedException();
        }

        public override List<Tag> GetTags(Image image)
        {
            throw new NotImplementedException();
        }

        public override List<Tag> GetTags(Member member)
        {
            throw new NotImplementedException();
        }
    }
}